package Arrays;

/**
 * 作者:hfj
 * 功能:125.验证字符串
 * 日期: 2025/10/27 9:22
 */
public class IsPalindrome {
    public static void main(String[] args) {
        String s = "ab_a";
        System.out.println(isPalindrome(s));
    }

    public static boolean isPalindrome(String s) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if ((s.charAt(i) >= 65 && s.charAt(i) <= 90) || (s.charAt(i) >= 48 && s.charAt(i) <= 57) || (s.charAt(i) >= 97 && s.charAt(i) <= 122)){
                builder.append(s.charAt(i));
            }
        }
        String s1 = "",s2 = "";
        s1 += builder;
        StringBuilder builder1 = builder.reverse();
        s2 += builder1;
        String tar = s1.toLowerCase();
        String temp = s2.toLowerCase();
        if (tar.equals(temp)){
            return true;
        }
        return false;
    }
}
